# -*- coding: utf-8 -*-
# @author: wch
# @file: drawshape.py
# @time: 2023/2/8 10:27
import numpy as np
import cv2


# 基本功能：
# 1. 可以画线：用户按下L键，即选择画线，滑动鼠标可以画线
# 2.

# 设置回调函数
def mouse_callback(event, x, y, flags, userdata):
    print(event, x, y, flags, userdata)


# 创建窗口
cv2.namedWindow("drawshape", cv2.WINDOW_NORMAL)
cv2.resizeWindow("drawshape", 640, 360)

# 设置鼠标回调
cv2.setMouseCallback("drawshape", mouse_callback, "123")

# 显示窗口和背景
img = np.zeros((460, 640, 3), np.uint8)

while True:
    cv2.imshow("drawshape", img)
    key = cv2.waitKey(0) & 0xFF
    if key == ord("q"):
        break
    elif key == ord("l"):
        cv2.line(img, (100, 100), (200, 200), (255, 0, 0), 1)
    elif key == ord("r"):
        cv2.rectangle(img, (100, 100), (200, 200), (255, 0, 0), -1)
    elif key == ord("c"):
        cv2.circle(img, (100, 100), 50, (0, 0, 255), 3, -1)
    else:
        pass
cv2.destroyAllWindows()
